package com.zqh.cycklicBarrier;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author 曾庆红
 * {@code @date} 2023-10-14 11:34
 */

public class T1 {
    public static void main(String[] args) {
        CyclicBarrier barrier = new CyclicBarrier(20,()->{
            System.out.println("满人");
        });
        for(int i = 0; i<100; i++){
            new Thread(()->{
                try {
                    barrier.await();
                    //在barrier满了之后才会向下执行
                    System.out.println(Thread.currentThread().getName());
                } catch (InterruptedException | BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
